package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import connection.JDCConnection;

import model.Seance;

public class SeanceDAO {
	
	
	public Seance getSeance(JDCConnection connection , int idSeance) {
		Statement stmt;
		ResultSet rs;
		Seance seance = new Seance();

		try {

			stmt = connection.createStatement();

			rs = stmt.executeQuery("SELECT * FROM Seance where idSeance="+idSeance);
			while (rs.next()) {
				
				
				seance.setIdSeance(rs.getInt("idSeance"));
				seance.setDebut(rs.getInt("debut"));
				seance.setFin(rs.getInt("fin"));
				seance.setType(rs.getInt("type"));
				seance.setIdGroupe(rs.getInt("idGroupe"));
				seance.setJour(rs.getInt("jour"));
				seance.setDuree(seance.getFin() - seance.getDebut());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return seance;
	}
	

	public ArrayList<Seance> getSeanceByGroupeId(JDCConnection connection , int idGroupe) {
		Statement stmt;
		ResultSet rs;
		ArrayList<Seance> list =new ArrayList<Seance> () ;
		

		try {

			stmt = connection.createStatement();

			rs = stmt.executeQuery("SELECT * FROM Seance where idGroupe="+idGroupe);
			while (rs.next()) {
				Seance seance = new Seance();
				
				seance.setIdSeance(rs.getInt("idSeance"));
				seance.setDebut(rs.getInt("debut"));
				seance.setFin(rs.getInt("fin"));
				seance.setType(rs.getInt("type"));
				seance.setIdGroupe(rs.getInt("idGroupe"));
				seance.setJour(rs.getInt("jour"));
				seance.setDuree(seance.getFin() - seance.getDebut());
				//ajout a la liste
				list.add(seance);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list;
	}
	
}
